$(function(){
    /*var url = {};
    var qZoneOpt = {
        url:"www.baidu.com",
        summary:'欢迎进入',
        title:"网站名字",
        style:'203'
    }

    var sinaWbOpt = {
        url:"www.baidu.com",
        title:"网站名字",
        searchpic:false,
        appkey:'652950352'
    }

    $(".share_iconImg.share_qzone").on('click',function(){
        //执行QQ分享
        var s = [];
        for(var i in qZoneOpt){
            s.push(i + '=' + encodeURIComponent(qZoneOpt[i]||''));
        }
        url = "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?"+s.join('&');
        window.open(url);
    });

    $(".share_iconImg.share_sinawb").on('click',function(){
        //执行新浪分享
        var s = [];
        for(var i in sinaWbOpt){
            s.push(i + '=' + encodeURIComponent(sinaWbOpt[i]||''));
        }
        url = "http://service.weibo.com/share/share.php?"+s.join('&');
        window.open(url);
    });*/

    $("#shi").sharePlugin({url:'www.baidu.com',title:'hello shi',summary:'happy'});

});

(function($){
    /*插件*/
    jQuery.fn.sharePlugin = function(options){
        var appKey = '652950352';
        var zQoneStyle = '203';
        var defaults = {
            share:['zqone','sinawb'],
            url:"",//需要转发网站的网址
            title:'',
            summary:'',
            searchpic:false
        };

        var opt = $.extend(defaults,options);


        var url = {};
        var qZoneOpt = {
            url:opt.url,
            summary:opt.summary,
            title:opt.title,
            style:zQoneStyle
        }

        var sinaWbOpt = {
            url:opt.url,
            title:opt.title,
            searchpic:opt.searchpic,
            appkey:appKey
        }

        var that = $(this);
        var shareText =  $("<span>").addClass("share_tips").text("分享到:");
        var ul = $("<ur>").addClass("warpShare");
        for(var type in  opt.share){
            switch (opt.share[type]) {
                case 'zqone':
                    var li = $("<li>");
                    var a = $("<a>").attr('title','分享到QQ空间');
                    var i = $("<i>").addClass('share_iconImg').addClass('share_qzone');
                    li.append(a.append(i));
                    ul.append(li);
                    break;
                case 'sinawb':
                    var li = $("<li>");
                    var a = $("<a>").attr('title','分享到新浪微博');
                    var i = $("<i>").addClass('share_iconImg').addClass('share_sinawb');

                    li.append(a.append(i));
                    ul.append(li);
                    break;
            }
        }

        $(that).append(shareText);
        $(that).append(ul);


        $(".share_iconImg.share_qzone").on('click',function(){
            //执行QQ分享
            var s = [];
            for(var i in qZoneOpt){
                s.push(i + '=' + encodeURIComponent(qZoneOpt[i]||''));
            }
            url = "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?"+s.join('&');
            window.open(url);
        });

        $(".share_iconImg.share_sinawb").on('click',function(){
            //执行新浪分享
            var s = [];
            for(var i in sinaWbOpt){
                s.push(i + '=' + encodeURIComponent(sinaWbOpt[i]||''));
            }
            url = "http://service.weibo.com/share/share.php?"+s.join('&');
            window.open(url);
        });

    }

})(jQuery);

